package Gui;
// from http://www.java-forums.org/awt-swing/6574-add-image-jframe.html
import java.awt.Dimension;
import java.awt.Graphics;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

import javax.swing.JPanel;

public class CenteredImagePanel extends JPanel {
	private BufferedImage m_image;

	public CenteredImagePanel(BufferedImage img){
		BufferedImage m_image= img;
		Dimension size = new Dimension(img.getWidth(null), img.getHeight(null));
		setPreferredSize(size);
		setMinimumSize(size);
		setMaximumSize(size);
		setSize(size);
		setLayout(null);
	}
	public CenteredImagePanel(String path) throws IOException{
			this(ImageIO.read(new File(path)));
	
	}

	public void paintComponent(Graphics g) {
		int x = (getWidth()-m_image.getWidth())/2;
		int y = (getHeight()-m_image.getHeight())/2;
		g.drawImage(m_image, x, y, null);
	}
}
